package net.zigin.nhi.could.waste.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import net.zigin.nhi.could.waste.dto.PageDto;
import net.zigin.nhi.could.waste.dto.WasteBaseDto;
import net.zigin.nhi.could.waste.dto.WasteCountDto;
import net.zigin.nhi.could.waste.service.WasteBaseService;

import net.zigin.nhi.could.waste.vo.JsonForResult;
import net.zigin.nhi.could.waste.vo.WasteBaseVo;
import net.zigin.nhi.could.waste.vo.WasteCountVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * WasteBase控制器类
 *
 * @author mgw1986
 * @version V1.0
 * @ClassName: WasteBaseController
 * @date 2021-9-20 17:17:58
 */
@Api(tags = "医废管理")
@RestController
@RequestMapping("/wasteBase")
public class WasteBaseController extends BaseController {
    @Autowired
    private WasteBaseService wasteBaseService;

    @ApiOperation("医废列表")
    @ApiImplicitParam(name = "wasteBaseDto", value = "医废信息", required = true, dataType = "WasteBaseDto")
    @PostMapping("/getList")
    public JsonForResult<List<WasteBaseVo>> getList(@RequestBody WasteBaseDto wasteBaseDto) {
        List<WasteBaseVo> list = wasteBaseService.getList(wasteBaseDto);
        Integer count = wasteBaseService.getCount(wasteBaseDto);
        return JsonForResult.<List<WasteBaseVo>>builder().data(list).total(count).success(true).build();
    }

    @ApiOperation("医废根据id删除")
    @ApiImplicitParam(name = "id", value = "医废id", required = true, dataType = "String")
    @DeleteMapping("/deleteById/{id}")
    public JsonForResult deleteById(@PathVariable String id) {
        wasteBaseService.deleteById(id);
        return JsonForResult.builder().success(true).build();
    }

    @ApiOperation("首页-每月")
    @GetMapping("/eachMonth")
    public JsonForResult<List<WasteCountVo>> eachMonth() {
        List<WasteCountVo> wasteCountVos = wasteBaseService.eachMonth();
        return JsonForResult.<List<WasteCountVo>>builder().data(wasteCountVos).success(true).build();
    }

    @ApiOperation("首页-周分类")
    @GetMapping("/weekClassify")
    public JsonForResult<List<WasteCountVo>> weekClassify() {
        List<WasteCountVo> wasteCountVos = wasteBaseService.weekClassify();
        return JsonForResult.<List<WasteCountVo>>builder().data(wasteCountVos).success(true).build();
    }

    @ApiOperation("首页-科室前15")
    @PostMapping("/fifteenDepart")
    @ApiImplicitParam(name = "wasteCountDto", value = "数量统计信息", required = true, dataType = "WasteCountDto")
    public JsonForResult<List<WasteCountVo>> fifteenDepart(@RequestBody WasteCountDto wasteCountDto) {
        List<WasteCountVo> wasteCountVos = wasteBaseService.fifteenDepart(wasteCountDto);
        return JsonForResult.<List<WasteCountVo>>builder().data(wasteCountVos).success(true).build();
    }

    @ApiOperation("首页-实时收集")
    @PostMapping("/collectList")
    @ApiImplicitParam(name = "pageDto", value = "分页信息", required = true, dataType = "PageDto")
    public JsonForResult<List<WasteBaseVo>> collectList(@RequestBody PageDto pageDto) {
        List<WasteBaseVo> wasteBaseVos = wasteBaseService.collectList(pageDto);
        return JsonForResult.<List<WasteBaseVo>>builder().data(wasteBaseVos).success(true).build();
    }

    @ApiOperation("首页-总量统计")
    @GetMapping("/situation")
    public JsonForResult<Map<String, Object>> situation() {
        Map<String, Object> result = wasteBaseService.situation();
        return JsonForResult.<Map<String, Object>>builder().data(result).success(true).build();
    }

    @ApiOperation("医废状态报表")
    @ApiImplicitParam(name = "wasteCountDto", value = "医废统计信息", required = true, dataType = "WasteCountDto")
    @PostMapping("/statusReport")
    public JsonForResult<List<WasteCountVo>> statusReport(@RequestBody WasteCountDto wasteCountDto) {
        List<WasteCountVo> wasteCountVos = wasteBaseService.statusReport(wasteCountDto);
        return JsonForResult.<List<WasteCountVo>>builder().data(wasteCountVos).success(true).build();
    }

    @ApiOperation("医废分类报表")
    @ApiImplicitParam(name = "wasteCountDto", value = "医废统计信息", required = true, dataType = "WasteCountDto")
    @PostMapping("/classifyReport")
    public JsonForResult<List<WasteCountVo>> classifyReport(@RequestBody WasteCountDto wasteCountDto) {
        List<WasteCountVo> wasteCountVos = wasteBaseService.classifyReport(wasteCountDto);
        return JsonForResult.<List<WasteCountVo>>builder().data(wasteCountVos).success(true).build();
    }

    @ApiOperation("医废分类科室报表")
    @ApiImplicitParam(name = "wasteCountDto", value = "医废统计信息", required = true, dataType = "WasteCountDto")
    @PostMapping("/classifyDepartReport")
    public JsonForResult<List<WasteCountVo>> classifyDepartReport(@RequestBody WasteCountDto wasteCountDto) {
        List<WasteCountVo> wasteCountVos = wasteBaseService.classifyDepartReport(wasteCountDto);
        return JsonForResult.<List<WasteCountVo>>builder().data(wasteCountVos).success(true).build();
    }

    @ApiOperation("导出报表")
    @ApiImplicitParam(name = "wasteCountDto", value = "医废统计信息", required = true, dataType = "WasteCountDto")
    @PostMapping("/exportList")
    public void exportList(@RequestBody WasteCountDto wasteCountDto, HttpServletResponse response) {
        wasteBaseService.exportList(wasteCountDto, response);
    }

    @ApiOperation("预警-箱出库预警详情")
    @ApiImplicitParam(name = "boxRecordId", value = "箱记录id", required = true, dataType = "String")
    @GetMapping("/warnInfoByBoxRecordId/{boxRecordId}")
    public JsonForResult<Map<String, Object>> warnInfoByBoxRecordId(@PathVariable String boxRecordId) {
        Map<String, Object> result = wasteBaseService.warnInfoByBoxRecordId(boxRecordId);
        return JsonForResult.<Map<String, Object>>builder().data(result).success(true).build();
    }

    @DeleteMapping("/remove/{id}")
    @ApiOperation("删除医废")
    @ApiImplicitParam(name = "id", value = "医废id", required = true, dataType = "String")
    public JsonForResult remove(@PathVariable String id) {
        wasteBaseService.remove(id);
        return JsonForResult.builder().success(true).build();
    }


}
